import React, {useEffect, useRef, useState} from 'react';

function Child(props) {

    // useEffect(async function(){
    //     console.log("挂载child组件成功");
    //     return function(){
    //         console.log("卸载child组件")
    //     }
    // },[])

    const [userName,setUserName] = useState("lisi");
    const h3Ref = useRef();
    useEffect(function(){
        console.log("更新child组件成功1",userName,h3Ref.current.innerText);
        return function(){
            console.log("更新child组件成功2",userName,h3Ref.current.innerText);
        }
    },[userName])
    return (
        <div>
            <h3 ref={h3Ref} onClick={()=>setUserName(userName+"!")}>{userName}</h3>
        </div>
    );
}

export default Child;